package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsRoleMapper;
import com.qf.pojo.DtsRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author fy
 * @version V1.0
 * @Project workspace
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/20 22:34
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private DtsRoleMapper dtsRoleMapper;
    @Override
    public Set<String> queryByIds(Integer[] ids) {

        //如果ids为空，直接返回空的集合
        if (ids ==null||ids.length==0){
            return new HashSet<String>();
        }

        QueryWrapper<DtsRole> queryWrapper = new QueryWrapper();
        //查询条件相当于where in (1,2,3,4)
        queryWrapper.in("id",ids);
        //查询没有被删除的
        queryWrapper.eq("deleted", false);
        //查询被启用的
        queryWrapper.eq("enabled", true);
        List<DtsRole> list = dtsRoleMapper.selectList(queryWrapper);
        Set<String > roleSet = new HashSet<>();
        //将list集合转换成shiro框架支持的set集合
        if (list!=null){
            for (DtsRole dtsRole : list) {
                roleSet.add(dtsRole.getName());
            }
        }

        return roleSet;
    }
}
